import requests

# UA伪装
# UA:User-Agent,模拟浏览器发起请求
if __name__ == '__main__':
    # 请求url
    url = 'https://www.sogou.com/web'
    # 请求头
    headers = {
        'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36"
    }
    # 处理url请求参数：封装到字典中
    kw = input('enter a word:')
    params = {
        'query': kw
    }
    # 传入参数为：url，get参数，请求头
    response = requests.get(url=url, params=params, headers=headers)

    page_text = response.text
    fileName = kw + '.html'
    with open(fileName, 'w', encoding='utf-8') as fp:
        fp.write(page_text)
    print(fileName, '保存成功!!!')
